# -*- coding: utf-8 -*-

def CheckKeys(keys, endi):
    n = len(keys)
    j = n - 1
    while j >= 0: